package com.pubsys.main.client.componentes.campodados;



import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.ListBox;

import java.util.Date;

public class DataListBox extends Composite {

	private static DataListBoxUiBinder uiBinder = GWT
			.create(DataListBoxUiBinder.class);
	@UiField ListBox listMes;
	@UiField ListBox listAno;
	@UiField ListBox listDia;

	interface DataListBoxUiBinder extends UiBinder<Widget, DataListBox> {
	}

	public DataListBox() {
		initWidget(uiBinder.createAndBindUi(this));
		inicializaListas();
	}
	

	@SuppressWarnings("deprecation")
	private void inicializaListas(){
		for(int i =1; i <= 31; i++){
			listDia.addItem(String.valueOf(i));
		}
		for(int j =1; j <= 12; j++){
			listMes.addItem(String.valueOf(j));
		}
		Date data = new Date();
		int ano = 1900 + data.getYear();
		System.out.println("Ano: "+ ano);
		for(int k =1900; k <= ano; k++){
			listAno.addItem(String.valueOf(k));
		}
		int dia = data.getDate();
		listDia.setSelectedIndex(dia -1);
		int mes = data.getMonth();
		listMes.setSelectedIndex(mes);
		listAno.setSelectedIndex(listAno.getItemCount()-1);
	}
	
	public Date getData(){
		Date data = new Date();
		
		data.setDate(listDia.getSelectedIndex()+1);
		data.setMonth(listMes.getSelectedIndex());
		data.setYear(listAno.getSelectedIndex());
		
		return data;
	}
	

}
